package view;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Observable;

import javax.swing.JButton;
import javax.swing.JPanel;

import model.Auction;
import model.Item;
import model.NonProfit;
import model.WestPanelEnum;

import javax.swing.JLabel;

import controller.ACSystem;

import javax.swing.border.LineBorder;

import java.awt.Color;

/**
 * The auction verification pane
 * 
 * @author Bob Landowski
 */
@SuppressWarnings("serial")
public class AuctionVerificationPane extends JPanel {

	/** The organization */
	private String my_organization;

	/** The first name */
	private String my_first_name;

	/** The last name */
	private String my_last_name;

	/** The phone */
	private String my_phone;

	/** The auction */
	private Auction my_auction = new Auction(null, null, null, null);

	/** The date */
	private String my_date;

	/** The aution number */
	@SuppressWarnings("unused")
	private int my_auction_number;

	/** The start time */
	@SuppressWarnings("unused")
	private String my_start_time;

	/** The end time */
	@SuppressWarnings("unused")
	private String my_end_time;

	/** The owner */
	@SuppressWarnings("unused")
	private NonProfit my_owner;

	/** The items */
	@SuppressWarnings("unused")
	private ArrayList<Item> my_items;

	/** The duration */
	private int my_duration;

	/** The number of items */
	@SuppressWarnings("unused")
	private int my_numberOfItems;

	/** The ACcontroller */
	private ACSystem my_ACcontroller;

	/** The start time */
	private String my_start_time_string;

	/** The end time */
	private String my_end_time_string;

	/** The contact name label */
	private JLabel my_contact_name;

	/** The organization name label */
	private JLabel my_organization_name;

	/** The contact phone label */
	private JLabel my_contact_phone;

	/** The duration label */
	private JLabel durationLabel;

	/** The aution date label */
	private JLabel auctionDateLabel;

	/** The start time label */
	private JLabel starttimeLabel;

	/** The end time label */
	private JLabel endTimeLabel;

	/** The number of items labels */
	private JLabel numOfItemsLabel;

	/** The west panel observable */
	private WestPanelObservable wpo = new WestPanelObservable();

	/**
	 * The auction verification pane constructor
	 */
	public AuctionVerificationPane(final ACSystem the_ACcontroller) {
		setBorder(new LineBorder(new Color(0, 0, 0), 5));
		my_ACcontroller = the_ACcontroller;
		setLayout(null);

		JLabel auctiondisplayLabel = new JLabel(
				"Auction Central Auction Verification");
		auctiondisplayLabel.setBounds(81, 16, 233, 20);
		add(auctiondisplayLabel);

		setPreferredSize(new Dimension(500, 500));

		JLabel organizationLabel = new JLabel("Organization");
		organizationLabel.setBounds(15, 64, 99, 20);
		add(organizationLabel);

		my_organization_name = new JLabel(my_organization);
		my_organization_name.setBounds(159, 64, 173, 20);
		my_organization_name.setText(my_organization);
		add(my_organization_name);

		JLabel contactPersonLabel = new JLabel("Contact person:");
		contactPersonLabel.setBounds(15, 94, 117, 20);
		add(contactPersonLabel);

		my_contact_name = new JLabel(my_first_name + " " + my_last_name);
		my_contact_name.setBounds(159, 94, 198, 20);
		add(my_contact_name);

		JLabel contactPhoneLabel = new JLabel("Contact Phone:");
		contactPhoneLabel.setBounds(15, 124, 117, 20);
		add(contactPhoneLabel);

		my_contact_phone = new JLabel(my_phone);
		my_contact_phone.setBounds(159, 124, 135, 20);
		add(my_contact_phone);

		JLabel dateLabel = new JLabel("Auction Date:");
		dateLabel.setBounds(15, 154, 99, 20);
		add(dateLabel);

		JLabel auctionStartTimeLabel = new JLabel("Auction start time:");
		auctionStartTimeLabel.setBounds(15, 184, 146, 20);
		add(auctionStartTimeLabel);

		JLabel AnticipatedNumberLabel = new JLabel(
				"Anticipated number of items:");
		AnticipatedNumberLabel.setBounds(15, 274, 213, 20);
		add(AnticipatedNumberLabel);

		JButton submitButton = new JButton("Submit");
		submitButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				my_ACcontroller.getAuctionCalendar().addAuction(my_auction);
				my_ACcontroller.setWestPanel(WestPanelEnum.CALENDAR);
				my_ACcontroller.getMainFrame().westPanelState(new Object());
				((NonProfit) my_ACcontroller.getCurrentUser())
						.setCurrentAuction(my_auction);
				my_ACcontroller.getMainFrame().my_EastPanelNP.disableMe();
			}
		});
		submitButton.setBounds(30, 345, 115, 29);
		add(submitButton);

		JButton cancelButton = new JButton("Cancel");
		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				my_ACcontroller.setWestPanel(WestPanelEnum.CALENDAR);
				my_ACcontroller.getMainFrame().westPanelState(new Object());
			}
		});
		cancelButton.setBounds(267, 345, 115, 29);
		add(cancelButton);

		auctionDateLabel = new JLabel(my_date);
		auctionDateLabel.setBounds(149, 154, 145, 20);
		add(auctionDateLabel);

		starttimeLabel = new JLabel(my_start_time_string);
		starttimeLabel.setBounds(159, 184, 117, 20);
		add(starttimeLabel);

		endTimeLabel = new JLabel(my_end_time_string);
		endTimeLabel.setBounds(165, 244, 111, 20);
		add(endTimeLabel);

		JLabel auctionDurationLabel = new JLabel("Auction duration (in hours):");
		auctionDurationLabel.setBounds(15, 214, 205, 20);
		add(auctionDurationLabel);

		numOfItemsLabel = new JLabel("");
		numOfItemsLabel.setBounds(235, 274, 111, 20);
		add(numOfItemsLabel);

		JLabel auctionEndTimeLabel = new JLabel("Auction End Time:");
		auctionEndTimeLabel.setBounds(15, 244, 135, 20);
		add(auctionEndTimeLabel);

		durationLabel = new JLabel(my_duration + "");
		durationLabel.setBounds(235, 214, 69, 20);
		add(durationLabel);
	}

	/**
	 * The getObjectData method
	 */
	public void getObjectData(Object the_object) {
		my_auction = (Auction) the_object;
		my_contact_name.setText(my_auction.getOwner().get_first_name() + " "
				+ my_auction.getOwner().get_last_name());
		my_contact_phone.setText(my_auction.getOwner().getMy_phone());
		my_date = null;// my_auction.getDate().toString();
		auctionDateLabel.setText(my_auction.getDate().toString());
		my_auction_number = 0;// my_auction.getAuctionNumber();
		starttimeLabel.setText(my_auction.getStartTime());
		endTimeLabel.setText(my_auction.getEndTime());
		my_organization_name
				.setText(my_auction.getOwner().getMy_organization());
		my_items = my_auction.getItemList();
		durationLabel.setText(Integer.toString(my_auction.getDuration()));
		numOfItemsLabel.setText(Integer.toString(my_auction
				.getRequestedAmount()));
	}

	/**
	 * WestPanelObservable class
	 */
	private class WestPanelObservable extends Observable {

		/**
		 * WestPanelObservable constructor
		 */
		WestPanelObservable() {
			super();
		}

		void buttonClicked(Object o) {
			setChanged();
			notifyObservers(o);
			System.out.println("notified");
		}
	}
}